<template>
  <div id="goodslist">
    <div class="con">
      <!-- 头部 -->
      <div id="top">
        <h2>分类</h2>
        <p>
          <span class="iconfont">&#xf0112;</span>
          <span class="iconfont">&#xe71e;</span>
          <i class="line"></i>
        </p>
      </div>
      <!-- 搜索框 -->
      <div id="inp">
        <input type="text" class="iconfont" placeholder="按内容搜索" />
      </div>

      <!-- 主要内容 -->
      <main>
        <div class="left">
          <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="onLoad"
          >
            <van-cell v-for="(item,index) in sortlist" :key="index" :title="item.catename" :class="num==index?'cur':''" @click="changenum(index)" />
          </van-list>
        </div>
        <div class="right">
          <div class="box1 A">
            <h2>热门精选</h2>
            <p>
              <span v-for="(item,index) in secondlist"
              :key="index" @click="enter(item.id)">
                <img :src="$pre+item.img" alt="" />
                <i>{{item.catename}}</i>
              </span>
            </p>
          </div>
        </div>
      </main>
    </div>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
export default {
  data() {
    return {
      num:0,
      list: [],
      loading: false,
      finished: false,
    };
  },
  methods: {
    onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      setTimeout(() => {
        for (let i = 0; i < 10; i++) {
          this.list.push(this.list.length + 1);
        }
        this.loading = false;

        if (this.list.length >= 40) {
          this.finished = true;
        }
      }, 1000);
    },
    enter(id) {
      this.$router.push("/shoppinglist2?num="+id+"&type=2");
    },
    ...mapActions({
      reqChangeSortList: "goodslist/reqChangeSortList",
      reqChangeSecondlist: "goodslist/reqChangeSecondlist",
    }),
     changenum(index){
      this.num=index
      this.reqChangeSecondlist(this.num)
    }
  },
   computed:{
      ...mapGetters({
        sortlist:"goodslist/list",
        secondlist:"goodslist/secondlist",
      })
  },
  mounted(){
    this.reqChangeSortList()
    this.reqChangeSecondlist(this.num)
  }
};
</script>

<style scoped>
.con {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 7.5rem;
  margin: auto;
}
/*头部*/
#top {
  width: 5.5rem;
  height: 0.64rem;
  padding: 0.28rem 0.1rem 0.28rem 2rem;
  background-color: #ff6040;
  display: flex;
  color: #ffdfd8;
  justify-content: space-between;
  align-items: center;
  z-index: 1;
}
#top h2 {
  font-size: 0.32rem;
}
#top p {
  height: 0.64rem;
  width: 1.75rem;
  display: flex;
  border: 1px solid #ff8a6f;
  box-sizing: border-box;
  border-radius: 0.64rem;
  align-items: center;
  position: relative;
}
#top p span {
  width: 50%;
  height: 100%;
  text-align: center;
  line-height: 0.64rem;
}
#top p .line {
  width: 1px;
  height: 0.38rem;
  position: absolute;
  left: 0.87rem;
  top: 0.13rem;
  background-color: #fff;
}
#inp {
  width: 100%;
  height: 0.83rem;
  background: linear-gradient(#ff6344, #ff877b);
  padding: 0 0.2rem 0.2rem 0.2rem;
  box-sizing: border-box;
  position: fixed;
  left: 0;
  top: 1.2rem;
  z-index: 1;
}
#inp input {
  height: 0.63rem;
  width: 100%;
  border: 2px solid #e6e6e6;
  box-sizing: border-box;
  border-radius: 0.1rem;
  padding-left: 0.22rem;
}
#inp input::placeholder {
  color: #999999;
  font-size: 0.26rem;
}
main {
  margin-top:2rem ;
  display: flex;
  padding: 0 0 1.65rem 0;
}
main .left {
  width: 2.37rem;
  height: 100vh;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.55rem 0 0.3rem 0;
  align-items: center;
  box-sizing: border-box;
}
main .left  {
  color: #999999;
  font-size: 0.26rem;
}
main .left .cur {
  color: #ff6040;
  font-weight: bold;
}
main .right {
  width: 4.65rem;
  margin: 0rem 0.2rem 0 0.28rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
main .right .box1 {
  width: 100%;
  height: 4.36rem;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  padding: 0.2rem 0.2rem 0.25rem 0.2rem;
  box-sizing: border-box;
  margin-top: 0.3rem;
}
main .right h2 {
  font-size: 0.3rem;
  font-weight: bold;
}
main .right p {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
}
main .right p span {
  margin-left: 0.2rem;
  font-size: 0.22rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #999999;
}
main .right p span:nth-child(1),
main .right p span:nth-child(4) {
  margin-left: 0;
}
main .right p span img {
  width: 1.28rem;
  height: 1.28rem;
}
main .box2 {
  width: 100%;
  height: 2.6rem;
  background-color: #fff;
  display: flex;
  flex-direction: column;
  padding: 0.2rem 0.2rem 0.25rem 0.2rem;
  box-sizing: border-box;
  justify-content: space-between;
  margin-top: 0.3rem;
}
main .box2 h2 {
  font-size: 0.3rem;
  font-weight: bold;
}
main .box2 p {
  width: 100%;
  display: flex;
}
main .box2 p span {
  margin-left: 0.2rem;
  font-size: 0.22rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #999999;
}
main .box2 p span:nth-child(1) {
  margin-left: 0;
}
main .box2 p span img {
  width: 1.28rem;
  height: 1.28rem;
}
</style>